import { Effect, Reducer, Subscription } from 'umi';

export interface IndexModelState {
  titleName: string;
}

export interface IndexModelType {
  namespace: 'title';
  state: IndexModelState;
  effects: {
    // query: Effect;
  };
  reducers: {
    changeName: Reducer;
    // save: Reducer<IndexModelState>;
    // 启用 immer 之后
    // save: ImmerReducer<IndexModelState>;
  };
  subscriptions: { setup: Subscription };
}

const IndexModel: IndexModelType = {
  namespace: 'title',

  state: {
    titleName: '首页1',
  },

  effects: {
    // *query({ payload }, { call, put }) {},
  },
  reducers: {
    // save(state, action) {
    //   return {
    //     ...state,
    //     ...action.payload,
    //   };
    // },
    changeName(state, action) {
      return {
        ...state,
        titleName: action.payload,
      };
    },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {
        // if (pathname === '/') {
        //   dispatch({
        //     type: 'query',
        //   });
        // }
        // 引入menuList
        // 做menuList遍历，再将对应的title给到titleName
      });
    },
  },
};

export default IndexModel;
